using System;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;

namespace ASPNETVN.PORTAL.Modules.NEWS.Controls
{
    public partial class ItemManager : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hlAddNew.NavigateUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "page=AddEditItem");
            }
        }

        protected void gvItems_PageIndexChanged(object sender, EventArgs e)
        {
            gvItems.SelectedIndex = -1;
        }

        protected void cbStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvItems.SelectedIndex = -1;
            gvItems.Columns[gvItems.Columns.Count - 3].Visible = cbStatus.SelectedValue != "Published";            
        }

        
        protected void gvItems_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Approve")
            {
                Components.Item.Approve(Convert.ToInt32(e.CommandArgument));
                gvItems.DataBind();
                gvItems.SelectedIndex = -1;
            }
            else if (e.CommandName == "Edit")
            {
                Response.Redirect(HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, Convert.ToInt32(e.CommandArgument), "page=AddEditItem"));
            }
        }

        protected void hfModuleID_Init(object sender, EventArgs e)
        {
            hfModuleID.Value = this.ModuleID.ToString();
        }
    }
}